import request from '@/utils/requestblock'


export function getCCList(pageNum, pageSize) {
  let data = {
    'pageNum': pageNum,
    'pageSize': pageSize
  };
  return request({
    url: '/chaincode/list',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },

  })
}

export function getAllCCList() {
  return request({
    url: '/chaincode/count',
    method: 'post',
    data: '',
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function findChaincode(chainCodeName, status) {
  let data = {
    'chainCodeName': chainCodeName,
    'status': status
  };
  return request({
    url: 'chaincode/chaincodeQuery',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function installChaincode(peers, channelName, chainCodeName, chainCodeVersion) {
  let data = {
    "peers": peers,
    "channelName": channelName,
    "chainCodeName": chainCodeName,
    "chainCodeVersion": chainCodeVersion
  };
  return request({
    url: 'chaincode/installResolution',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function getPeers() {
  return request({
    url: 'allPeerName',
    method: 'post',
    data: '',
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function getChannels() {
  return request({
    url: 'getAllChannelName',
    method: 'post',
    data: '',
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function getChannelNameByPeer(peers) {
  return request({
    url: 'getChannelNameByPeer',
    method: 'post',
    data: peers,
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function chainCodeStructList(chainCodeName, chainCodeVersion) {
  let data = {
    "chainCodeName": chainCodeName,
    "chainCodeVersion": chainCodeVersion
  };
  return request({
    url: 'chaincode/CCStructList',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function getChaincodeNameByPeer(peer) {
  // alert(peer);
  return request({
    url: 'chaincode/getChaincodeByPeer',
    method: 'post',
    data: JSON.stringify(peer),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


export function getInterfaceVCByChaincodeName(peerchaincodeName) {
  // alert(peerchaincodeName);
  return request({
    url: 'chaincode/getInterfaceVersionChannelByChaincodeName',
    method: 'post',
    data: JSON.stringify(peerchaincodeName),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function queryResolution(peer, interfaceName, channel, chaincodeName, args) {
  let data = {
    "peer": peer,
    "interfaceName": interfaceName,
    "channelName": channel,
    "chainCodeName": chaincodeName,
    "args": args
  };
  return request({
    url: 'chaincode/queryResolution',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function invokeResolution(peer, interfaceName, channel, chaincodeName, args) {
  let data = {
    "peer": peer,
    "interfaceName": interfaceName,
    "channelName": channel,
    "chainCodeName": chaincodeName,
    "args": args
  };
  return request({
    url: 'chaincode/invokeResolution',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


export function AllCCInstallInfo(chaincodeName) {
  let data = {
    "chainCodeName": chaincodeName,
  };
  return request({
    url: 'chaincode/allCCInfoInstalled',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


export function upgradeResolution(peer, peerWithOrgs, channel, chaincodeName, version, args, upload) {
  let data = {
    "peers": peer,
    "peerWithOrgs": peerWithOrgs,
    "channels": channel,
    "chainCodeName": chaincodeName,
    "chainCodeVersion": version,
    "args": args,
    "upload": upload
  };
  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/upgradeResolution',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function showDetail(chaincodeName, version) {
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": version
  };
  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/CCDetail',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


export function getCCStructList(chaincodeName, chaincodeVersion) {
  // alert("1234");
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chaincodeVersion
  };

  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/CCStructList',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function addCCNew(chaincodeName, chaincodeVersion) {
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chaincodeVersion
  };
  return request({
    url: 'chaincode/add',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}
//合约上传
export function uploadCC(data) {
  // let data={
  //
  // };
  return request({
    url: 'chaincode/upload',
    method: 'post',
    data: data,
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}
//合约上传确定按钮
export function uploadCCSure(chaincodeName, chaincodeVersion, Interfaces, upload) {
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chaincodeVersion,
    "interfaces": Interfaces,
    "upload": upload
  };
  return request({
    url: 'chaincode/uploadSure',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


//删除合约
export function deleteChaincode(chaincodeName, status, version) {
  // alert("1234");
  let data = {
    "chainCodeName": chaincodeName,
    "status": status,
    "chainCodeVersion": version
  };

  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/deleteChaincode',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}
//合约保存
export function saveChainCode(chaincodeName, chainCodeVersion, structList) {
  // alert("1234");
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chainCodeVersion,
    "structList": structList
  };
  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/updateInterface',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

// 提交
export function submitUpdateInterface(chaincodeName, chainCodeVersion, structList) {
  // alert("1234");
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chainCodeVersion,
    "structList": structList
  };
  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/submintUpdateInterface',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}


export function submitUpgradeChaincode(chaincodeName, chainCodeVersion, structList) {
  // alert("1234");
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chainCodeVersion,
    "structList": structList
  };
  // alert(JSON.stringify(data));
  return request({
    url: 'chaincode/submitUpgradeChaincode',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

// 合约名称及版本校验
export function checkCCNameAndVersion(chaincodeName, chaincodeVersion) {
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chaincodeVersion
  };
  return request({
    url: 'chaincode/check',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function getPeerNameAndChannelNameByChaincode(chaincodeName, chainCodeVersion) {
  let data = {
    "chainCodeName": chaincodeName,
    "chainCodeVersion": chainCodeVersion
  };
  return request({
    url: 'PeerNameAndChannelNameByChaincode',
    method: 'post',
    data: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}

export function cleanData() {
  return request({
    url: 'chaincode/cleanData',
    method: 'post',
    data: '',
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
  })
}
